package com.ddtech.business.web.controller;

import com.ddtech.annotation.AnonymousAccess;
import com.ddtech.business.web.entity.Banner;
import com.ddtech.business.web.query.BannerQuery;
import com.ddtech.business.web.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author bin_pu
 * @since 2023-03-09
 */
@Api(tags = "业务-轮播图")
@RestController
@RequestMapping("/web/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @ApiOperation(value = "分页查询轮播图")
    @GetMapping(value = "/page-list")
    public ResponseEntity getPageList(BannerQuery bannerQuery) {
        return new ResponseEntity(bannerService.pageList(bannerQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "分页查询轮播图、PC端、APP端")
    @GetMapping(value = "/page-list-pc")
    @AnonymousAccess
    public ResponseEntity getPageListPc(BannerQuery bannerQuery) {
        return new ResponseEntity(bannerService.pageListPc(bannerQuery), HttpStatus.OK);
    }



    @ApiOperation(value = "新增轮播图")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody Banner banner) {
        bannerService.create(banner);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "删除轮播图")
    @PostMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        bannerService.del(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
